package hotel.meituan.oversea.biz.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import hotel.base.oversea.constant.CommonConstants;
import hotel.base.oversea.constant.MeituanConstants;
import hotel.base.oversea.constant.enums.CommonEnums;
import hotel.base.oversea.constant.enums.MessageEnums;
import hotel.base.oversea.constant.enums.MtHotelEnums;
import hotel.base.oversea.dto.meituan.MtHotelDetailDto;
import hotel.base.oversea.service.impl.BaseServiceImpl;
import hotel.base.oversea.utils.*;
import hotel.base.oversea.vo.meituan.MtHotelDownVo;
import hotel.base.oversea.vo.meituan.MtHotelRoomDeatilVo;
import hotel.base.oversea.vo.meituan.MtHotelRoomDownVo;
import hotel.base.oversea.vo.meituan.request.room.MtHotelRealRoomVo;
import hotel.meituan.oversea.api.dto.MtHotelDto;
import hotel.meituan.oversea.api.entity.*;
import hotel.meituan.oversea.api.vo.up.response.hotel.*;
import hotel.meituan.oversea.biz.config.service.RedisService;
import hotel.meituan.oversea.biz.mapper.*;
import hotel.meituan.oversea.biz.service.MtHotelRoomService;
import hotel.meituan.oversea.biz.service.MtHotelService;
import hotel.meituan.oversea.biz.task.MeituanSaveApiLogTask;
import hotel.meituan.oversea.biz.utils.MtUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisConnectionUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.web.client.RestTemplate;
import tk.mybatis.mapper.entity.Example;

import java.util.*;

@Slf4j
@Service
public class MtHotelServiceImpl extends BaseServiceImpl implements MtHotelService {
    @Autowired
    private MtHotelMapper mtHotelMapper;
    @Autowired
    private MtHotelRoomService mtHotelRoomService;
    @Autowired
    private MtHotelGoodsRoomUpDownLogMapper mtHotelGoodsRoomUpDownLogMapper;
    @Autowired
    private MtHotelDetailMapper mtHotelDetailMapper;

    @Autowired
    private MtHotelDetailBasicLogMapper mtHotelDetailBasicLogMapper;

    @Autowired
    private MtHotelDetailOperLogMapper mtHotelDetailOperLogMapper;
    @Autowired
    private MtHotelDetailBasicRoomRealInfoMapper mtHotelDetailBasicRoomRealInfoMapper;
    @Autowired
    private MtHotelRoomMapper mtHotelRoomMapper;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private RedisService redisService;

    @Autowired
    MeituanSaveApiLogTask meituanSaveApiLogTask;


    /**
     * 防止更新数据遗漏，所以pageIds order asc返回ids
     *
     * @param index
     * @param pageSize
     * @return
     */
    @Override
    public Result<Object> queryPageHotelIds(int index, int pageSize) {
        Map res = new HashMap();
        /*int allSize = redisTemplate.opsForValue().get(MeituanConstants.REDIS_MT_HOTEL_BIZ+"MT_HOTEL_IDS_SIZE")
                ==null?0:(int)redisTemplate.opsForValue().get(MeituanConstants.REDIS_MT_HOTEL_BIZ+"MT_HOTEL_IDS_SIZE");
        if(allSize<=0){
            Example example = new Example(MtHotel.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("state",0);
            List<MtHotel> all = mtHotelMapper.selectByExample(example);
            allSize = all.size();
        }*/

        Map<String, Integer> map = new HashMap();
        map.put("index", index);
        map.put("pageSize", pageSize);
        List<Long> ids = new ArrayList<>();
        List<MtHotelDto> list = mtHotelMapper.queryPageDto(map);
        if (null != list && list.size() > 0) {
            for (MtHotelDto dto : list) {
                ids.add(Long.valueOf(dto.getHotelId()));
            }
            res.put("hotelIds", ids);
        } else {
            res.put("hotelIds", null);
        }
        return new Result<>(res);
    }

    String a = "";

    /**
     * 请求获取酒店ids数据
     *
     * @param maxId
     * @param pageSize
     * @return maxId 标记值，用于下一页查询。当maxId为-1时，表示已经查询到最后一页
     * hotelIds  可分销的酒店ID列表
     * @description 当前查询下一页数据pageSize不变，maxId变更为上一次查询返回的maxId作为查询数据标识
     * @repsonse maxId = 0,pageSize=2
     * {"code":0,"message":"成功","partnerId":3,"result":{"maxId":27139528,"hotelIds":[184552193,2621481]}}
     * maxId=0,pageSize=10
     * {"code":0,"message":"成功","partnerId":3,"result":{"maxId":27139539,"hotelIds":[184552193,2621481,182455012,177736348,61342633,1572893,6815849,157288800,52953896,2621480]}}
     * 下一页上送maxId=27139539
     * {"code":2000,"message":"系统错误:上游接口异常","partnerId":3,"result":null}
     */
    @Override
    public Result<Object> getMtHotelIdsData(int maxId, int pageSize) {
        //接口地址:https://developer-distribution.meituan.com/distribution-open-platform/#/apiDocs/1/13/14
        //
        //业务参数
        String data = "{\"maxId\":" + maxId + ",\"pageSize\":" + pageSize + "}";
        //发起请求(美团查询酒店ID列表)
        String response = MtUtils.createParamsPost(data, MtHotelEnums.apiMethodEnum.METHOD_HOTEL_IDS.getMethod(), meituanSaveApiLogTask);
        //处理响应数据
        JSONObject responseJson = JSON.parseObject(response);
        MtHotelVo vo = null;
        if ("0".equals(String.valueOf(responseJson.get("code")))) {//判断是否请求成功
            JSONObject result = responseJson.getJSONObject("result");//获取结果
            if (null != result) {
                //业务处理，保存数据
                vo = JSON.parseObject(result.toString(), MtHotelVo.class);//把响应结果转为对象
                if (null != vo) {
                    List<Long> hotelIds = vo.getHotelIds();//获取,可分销的酒店列表
                    if (-1 == vo.getMaxId()) {
                        return new Result<>(vo);//maxId=-1 当前无数据且无下一页,则直接return
                    }
                    if (null != vo && hotelIds != null && hotelIds.size() > 0) {
                        return new Result<>(vo);//可分销的酒店列表不为空,也return
                    } else {
                        log.error("////////////////MTAPIERROR///////////////////酒店IDS接口数据异常 result is null");
                        return new Result<>("hotelIds null", CommonConstants.PARSE_ERROR);
                    }
                } else {
                    log.error("////////////////MTAPIERROR///////////////////酒店IDS接口数据异常 parse vo error");
                    return new Result<>("parse error", CommonConstants.PARSE_ERROR);
                }

            } else {
                log.error("////////////////MTAPIERROR///////////////////酒店IDS接口数据异常 result is null");
                return new Result<>("result is null", CommonConstants.PARSE_ERROR);
            }
        } else {
            return new Result<>(responseJson.getString("message"), CommonConstants.REQUEST_ERROR);
        }
    }

    @Override
    public Result<Object> saveHotelIds(Map<Integer, List<Long>> hoteIdsListMaps) {//入参:酒店ID集合
        Map<String, String> putRedisMap = new HashMap<>();
        for (Map.Entry<Integer, List<Long>> hotelIdsEntry : hoteIdsListMaps.entrySet()) {
            List<Long> hotelIds = hotelIdsEntry.getValue();
            Integer maxId = hotelIdsEntry.getKey();
            List<MtHotel> entityList = new ArrayList<>();
            for (Long hotelId : hotelIds) {
                MtHotel entity = new MtHotel();//新建一个[美团酒店信息]的bean
                //设置属性进去
                entity.setId(String.valueOf(UUID.randomUUID()));
                entity.setMtHotelId(String.valueOf(hotelId));
                entity.setState(CommonEnums.STATE_NORMAL.getCode());
                entity.setRemark(maxId + "");
                entity.setCreateTime(new Date());
                entity.setModifyTime(new Date());
                entityList.add(entity);
                putRedisMap.put(String.valueOf(hotelId), String.valueOf(hotelId));
            }
            //mtHotelMapper.insertList(entityList);
            mtHotelMapper.insertIgnoreBatch(entityList);//ignore 重复的不新增

        }
        Map<String, String> redisMap = null;
        try {
            redisMap = (Map<String, String>) redisTemplate.opsForValue().get(MeituanConstants.REDIS_MT_HOTEL_IDS);
        } catch (Exception var6) {
            var6.printStackTrace();
        } finally {
            RedisConnectionUtils.unbindConnection(this.redisTemplate.getConnectionFactory());
        }

        if (null != redisMap && redisMap.size() > 0) {
            redisMap.putAll(putRedisMap);
        } else {
            redisMap = putRedisMap;//redisMap为空的话,就直接使用putRedisMap
        }
        try {
            redisTemplate.opsForValue().set(MeituanConstants.REDIS_MT_HOTEL_IDS, redisMap);
        } catch (Exception var6) {
            var6.printStackTrace();
        } finally {
            RedisConnectionUtils.unbindConnection(this.redisTemplate.getConnectionFactory());
        }

        return new Result<>();
    }

    /*public ResultApiVo saveGetMtHotelIdsData(int maxId, int pageSize) {
        //业务参数
        String data = "{\"maxId\":" + maxId + ",\"pageSize\":" + pageSize + "}";
        return MtUtils.getResult(data, MeituanConstants.METHOD_HOTEL_IDS, response -> {
            MtBaseResponse<MtHotelVo> mtBaseResponse = JSONUtils.toBean(response, MtBaseResponse.class);
            if (MtUtils.isSuccess(mtBaseResponse)) {
                MtHotelVo vo = mtBaseResponse.getResult();
                if (vo == null) {
                    return new ResultApiVo(ApiConstans.CODE_ERROR, "parse error", vo);
                }
                saveHotelIds(vo.getHotelIds(), vo);
                return new ResultApiVo(vo);
            } else {
                return new ResultApiVo(ApiConstans.CODE_ERROR, "result is null", null);
            }
        });
    }*/
    /*private void saveHotelIds(List<Long> hotelIds, MtHotelVo vo) {
        if (CollectionUtils.isEmpty(hotelIds)) {
            throw new RuntimeException("hotelIds null");
        }
        List<MtHotel> entityList = new ArrayList<>();
        for (Long hotelId : hotelIds) {
            MtHotel entity = new MtHotel();
            entity.setId(String.valueOf(UUID.randomUUID()));
            entity.setMtHotelId(String.valueOf(hotelId));
            entity.setState(0);
            entity.setRemark(String.valueOf(vo.getMaxId()));
            entity.setCreateTime(new Date());
            entity.setModifyTime(new Date());
            entityList.add(entity);
        }
        //mtHotelMapper.insertList(entityList);
        mtHotelMapper.insertIgnoreBatch(entityList);//ignore 重复的不新增
    }*/

    /**
     * 请求获取酒店详情数据
     *
     * @param hotelIds 酒店ids 多个逗号隔开
     * @return
     */
    @Override
    public Result<Object> getMtHotelDetail(List<Long> hotelIds) {
        return getMtHotelDetail(hotelIds, null);
    }

    @Override
    public Result<Object> getMtHotelDetail(List<Long> hotelIds, Integer strategy) {
        //接口地址:https://developer-distribution.meituan.com/distribution-open-platform/#/apiDocs/1/13/19
        //业务参数
        String data = "";
        Map<String, Object> dataMap = new HashMap<>();
        dataMap.put("hotelIds", hotelIds);//请求对象赋值1
        if (null == strategy) {
            strategy = MtHotelEnums.detailStrategyEnum.ALL.getCode();//获取查询全部信息的code
        }
        dataMap.put("strategy", strategy);//请求对象赋值2
        data = JSONObject.toJSONString(dataMap);//请求对象转Json串
        //发起请求(请求获取酒店详情数据接口),取得响应结果
        String response = MtUtils.createParamsPost(data, MtHotelEnums.apiMethodEnum.METHOD_HOTEL_DETAIL.getMethod(), meituanSaveApiLogTask);
        //处理响应数据
        JSONObject responseJson = JSON.parseObject(response);
        List<MtHotelDetailVo> voList = null;
        if ("0".equals(String.valueOf(responseJson.get("code")))) {//判断是否请求成功
            JSONObject result = responseJson.getJSONObject("result");
            if (null != result) {
                //业务处理，保存数据
                String hotelDetails = result.getString("hotelDetails");
                if (StringUtils.isNotEmpty(hotelDetails)) {
                    try {
                        voList = JSON.parseArray(hotelDetails, MtHotelDetailVo.class);//把响应回来的数据转为bean对象
                    } catch (Exception e) {
                        log.error(e.getMessage(), e);
                        log.info("//////////////////////// 美团酒店详情异常 getMtHotelDetail parse error ：{}，{}", response, JSON.toJSONString(dataMap));
                        return new Result<>("parse error", CommonConstants.PARSE_ERROR);
                    }
                    if (null != voList && voList.size() > 0) {
                        //接口返回成功和酒店详情数据
                        return new Result<>(voList);//不为空就直接返回
                    } else {
                        log.info("//////////////////////// 美团酒店详情 getMtHotelDetail 该酒店查无信息 ：{}，{}", response, JSON.toJSONString(dataMap));
                        return new Result<>(voList);
                    }
                } else {
                    log.info("//////////////////////// 美团酒店详情异常 getMtHotelDetail hoteldetails null ：{}，{}", response, JSON.toJSONString(dataMap));
                    return new Result<>("hoteldetails null", CommonConstants.PARSE_ERROR);
                }
            } else {
                log.info("//////////////////////// 美团酒店详情异常 getMtHotelDetail result null ：{}，{}", response, JSON.toJSONString(dataMap));
                return new Result<>("result null", CommonConstants.PARSE_ERROR);
            }
        } else {
            log.info("//////////////////////// 美团酒店详情异常 getMtHotelDetail ：{}，{}", response, JSON.toJSONString(dataMap));
            return new Result<>(responseJson.getString("message"), CommonConstants.REQUEST_ERROR);
        }
    }

    /**
     * 保存酒店详情
     * 缓存：CommonConstants.MEITUAN_HOTEL_INFO
     *
     * @param redisHotelInfoMap：key=uuid标识 value=要保存的酒店详情vo
     * @return
     */
    @Override
    public Result<Object> saveHotelInfos(Map<String, List<MtHotelDetailVo>> redisHotelInfoMap) {
        Date now = new Date();
        //Map<String,List<MtHotelDetailVo>> getRedisMap = (Map<String,List<MtHotelDetailVo>>)redisService.get(MeituanConstants.REDIS_MT_HOTEL_DATA_WAIT_SAVE);
        try {
            Map redisAppendMap = new HashMap();
            for (Map.Entry<String, List<MtHotelDetailVo>> voListEntity : redisHotelInfoMap.entrySet()) {
                List<MtHotelDetailVo> voList = voListEntity.getValue();
                StringBuilder sb = new StringBuilder();
                List<MtHotelDetail> detailEntityList = new ArrayList<>();
                List<MtHotelDetailBasicRoomRealInfo> detailBasicRoomEntityList = new ArrayList<>();
                for (int i = 0; i < voList.size(); i++) {//
                    MtHotelDetailVo vo = voList.get(i);
                    MtHotelDetailBaseInfoVo baseInfoVo = vo.getBaseInfo();
                    MtHotelDetailExtendInfoPoiExtInfoVo poiExtInfoVo = vo.getExtendInfo().getPoiExtInfo();
                    MtHotelDetail entity = new MtHotelDetail();
                    entity.setId(StringUtil.getUUID());
                    entity.setMtHotelId(String.valueOf(baseInfoVo.getHotelId()));
                    entity.setMtHotelName(baseInfoVo.getPointName());
                    entity.setMtHotelDesc(baseInfoVo.getInfo());
                    entity.setMtHotelLongitude(String.valueOf(baseInfoVo.getLongitude()));
                    entity.setMtHotelLatitude(String.valueOf(baseInfoVo.getLatitude()));
                    entity.setMtHotelAddress(baseInfoVo.getAddress());
                    entity.setMtHotelCityName(baseInfoVo.getCityName());
                    entity.setMtCityLocationId(String.valueOf(baseInfoVo.getCityLocationId()));
                    entity.setMtLocationName(baseInfoVo.getLocationName());
                    entity.setMtAvgScore(baseInfoVo.getAvgScore());
                    entity.setMtPhone(baseInfoVo.getPhone());
                    entity.setMtOpeninfo(baseInfoVo.getOpenInfo());
                    entity.setMtCloseStatus(baseInfoVo.getCloseStatus());
                    entity.setMtFrontImage(baseInfoVo.getFrontImage());
                    entity.setMtBrandId(baseInfoVo.getBrandId());
                    entity.setMtBrandName(baseInfoVo.getBrandName());
                    entity.setMtOpenDate(poiExtInfoVo.getOpenDate());
                    entity.setMtDecorationDate(poiExtInfoVo.getDecorationDate());
                    entity.setMtRoomNum(poiExtInfoVo.getRoomNum());
                    entity.setMtFloorNum(poiExtInfoVo.getFloorNum());
                    entity.setMtHotelStar(poiExtInfoVo.getHotelStar());
                    entity.setMtHotelCheckinTimeBegin(poiExtInfoVo.getCheckinTimeBegin());
                    entity.setMtHotelCheckinTimeEnd(poiExtInfoVo.getCheckinTimeEnd());
                    entity.setMtStatusType(MtHotelEnums.statusTypeEnum.UP.getCode());
                    entity.setState(CommonEnums.STATE_NORMAL.getCode());
                    entity.setRemark("");
                    entity.setCreateTime(now);
                    entity.setModifyTime(now);

                    detailEntityList.add(entity);

                    List<MtHotelDetailRoomInfoVo> roomRealVoList = vo.getRoomInfos();
                    if (null != roomRealVoList && roomRealVoList.size() > 0) {
                        for (MtHotelDetailRoomInfoVo roomInfoVo : roomRealVoList) {
                            MtHotelDetailBasicRoomRealInfoVo realVo = roomInfoVo.getRoomBaseInfo();
                            MtHotelDetailBasicRoomRealInfo realInfoEntity = new MtHotelDetailBasicRoomRealInfo();
                            realInfoEntity.setId(StringUtil.getUUID());
                            realInfoEntity.setMtHotelId(realVo.getHotelId());
                            realInfoEntity.setMtFalseRoomId(realVo.getRoomId());
                            realInfoEntity.setMtRealRoomId(realVo.getRoomId());
                            /*realInfoEntity.setMtRoomName(realVo.getRoomName());
                            realInfoEntity.setMtRoomType(realVo.getRoomType());
                            realInfoEntity.setMtRoomDesc(realVo.getRoomDesc());
                            realInfoEntity.setMtUseableArea(realVo.getUseableArea());
                            realInfoEntity.setMtCapacity(realVo.getCapacity());
                            realInfoEntity.setMtWindow(realVo.getWindow());
                            realInfoEntity.setMtWindowView(realVo.getWindowView());
                            realInfoEntity.setMtWindowBad(realVo.getWindowBad());
                            realInfoEntity.setMtExtraBed(realVo.getExtraBed());
                            realInfoEntity.setMtFloor(realVo.getFloor());
                            realInfoEntity.setMtInternetWay(realVo.getInternetWay());
                            realInfoEntity.setMtWeekdayPrice(realVo.getWeekdayPrice());
                            realInfoEntity.setMtWeekendPrice(realVo.getWeekendPrice());*/
                            realInfoEntity.setState(CommonEnums.STATE_NORMAL.getCode());
                            realInfoEntity.setRemark("");
                            realInfoEntity.setCreateTime(now);
                            realInfoEntity.setModifyTime(now);
                            detailBasicRoomEntityList.add(realInfoEntity);
                        }
                    }

                    MtHotelDetailDto mtHotelDetailDto = new MtHotelDetailDto();
                    mtHotelDetailDto.setMtHotelId(entity.getMtHotelId());
                    mtHotelDetailDto.setMtHotelName(entity.getMtHotelName());
                    mtHotelDetailDto.setMtHotelLongitude(entity.getMtHotelLongitude());
                    mtHotelDetailDto.setMtHotelLatitude(entity.getMtHotelLatitude());
                    mtHotelDetailDto.setMtHotelCityName(entity.getMtHotelCityName());
                    mtHotelDetailDto.setMtLocationName(entity.getMtLocationName());
                    mtHotelDetailDto.setMtCityLocationId(entity.getMtCityLocationId());
                    mtHotelDetailDto.setMtAvgScore(entity.getMtAvgScore());
                    mtHotelDetailDto.setMtPhone(entity.getMtPhone());
                    mtHotelDetailDto.setMtOpeninfo(entity.getMtOpeninfo());
                    mtHotelDetailDto.setMtCloseStatus(entity.getMtCloseStatus());
                    mtHotelDetailDto.setMtFrontImage(entity.getMtFrontImage());
                    mtHotelDetailDto.setMtBrandId(entity.getMtBrandId());
                    mtHotelDetailDto.setMtBrandName(entity.getMtBrandName());
                    mtHotelDetailDto.setMtOpenDate(entity.getMtOpenDate());
                    mtHotelDetailDto.setMtDecorationDate(entity.getMtDecorationDate());
                    mtHotelDetailDto.setMtRoomNum(entity.getMtRoomNum());
                    mtHotelDetailDto.setMtFloorNum(entity.getMtFloorNum());
                    mtHotelDetailDto.setMtHotelStar(entity.getMtHotelStar());
                    mtHotelDetailDto.setMtHotelCheckinTimeBegin(entity.getMtHotelCheckinTimeBegin());
                    mtHotelDetailDto.setMtHotelCheckinTimeEnd(entity.getMtHotelCheckinTimeEnd());
                    mtHotelDetailDto.setMtStatusType(entity.getMtStatusType());
                    redisAppendMap.put(mtHotelDetailDto.getMtHotelId(), mtHotelDetailDto);//entity.getMtHotelLongitude()+entity.getMtHotelLatitude()

                    sb.append("'" + mtHotelDetailDto.getMtHotelId() + "'");//拼接单引号,到数据库后台用in查询.
                    if (i != voList.size() - 1) {
                        sb.append(",");
                    }
                }
                //mtHotelDetailInfoMapper.insertList(entityList);
                //旧数据删除，插入新数据
                Map map = new HashMap();
                map.put("hotelIds", sb.toString());
                int delDel = mtHotelDetailMapper.deleteBatch(map);
                if (delDel != -1) {
                    mtHotelDetailMapper.insertList(detailEntityList);
                }
                int relDel = mtHotelDetailBasicRoomRealInfoMapper.deleteBatch(map);
                if (relDel != -1) {
                    mtHotelDetailBasicRoomRealInfoMapper.insertList(detailBasicRoomEntityList);
                }
            }
            //将所有酒店数据缓存到redis，对比数据使用
            //redisSaveUpdateMtHotelInfos(redisAppendMap);
            return new Result<>();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return new Result<>(e.getMessage(), CommonConstants.REQUEST_ERROR);
        }
    }

    private Map<String, String> findRealRoomIdByMtHotelIdFromRelationHotelRoomTable(String mtHotelId) {
        Example example = new Example(MtHotelGoodsPrice.class);
        Example.Criteria criteria = example.createCriteria();
        //更新静态信息
        criteria.andEqualTo("mtHotelId", mtHotelId);
        List<MtHotelDetailBasicRoomRealInfo> list = mtHotelDetailBasicRoomRealInfoMapper.selectByExample(example);
        Map<String, String> map = new HashMap<>();
        for (MtHotelDetailBasicRoomRealInfo d : list) {
            map.put(String.valueOf(d.getMtRealRoomId()), String.valueOf(d.getMtRealRoomId()));
        }
        return map;
    }

    private Map<String, String> localRealIdMapFromRoomApiTable(String mtHotelId) {
        Example example = new Example(MtHotelGoodsPrice.class);
        Example.Criteria criteria = example.createCriteria();
        //更新静态信息
        criteria.andEqualTo("mtHotelId", mtHotelId);
        List<MtHotelRoom> list = mtHotelRoomMapper.selectByExample(example);
        Map<String, String> map = new HashMap<>();
        for (MtHotelRoom d : list) {
            map.put(String.valueOf(d.getMtRoomId()), String.valueOf(d.getMtRoomId()));
        }
        return map;
    }

    @Override
    public Result<Object> saveBasicHotelInfo(List<MtHotelDetailVo> voList) {//一次酒店查询是最多支持20个
        Date now = new Date();
        try {
            StringBuilder sb = new StringBuilder();
            List<MtHotelDetail> entityList = new ArrayList<>();
            List<MtHotelDetailBasicRoomRealInfo> detailBasicRoomEntityList = new ArrayList<>();
            Map redisAppendMap = new HashMap();
            List<Long> hotelIds = new ArrayList<>();
            for (int i = 0; i < voList.size(); i++) {
                MtHotelDetailVo vo = voList.get(i);
                MtHotelDetailBaseInfoVo thisHotelDetailBaseInfo = vo.getBaseInfo();
                String mtHotelId = String.valueOf(thisHotelDetailBaseInfo.getHotelId());
                String newHotelName = thisHotelDetailBaseInfo.getPointName();//最新酒店名称
                String newHotelAddress = thisHotelDetailBaseInfo.getAddress();//最新酒店地址
                String newPhone = thisHotelDetailBaseInfo.getPhone();//最新酒店地址
                hotelIds.add(Long.valueOf(mtHotelId));
                //来自酒店与房型关联表的所有的真实房型id，
                /*Map<String,String> localRealIdMapFromRelationHotelRoomTable = findRealRoomIdByMtHotelIdFromRelationHotelRoomTable(mtHotelId);//当前数据库保存的房型数据
                Map<String,String> saleUpFailureMap = new HashMap<>();//上架房型失效了
                Map<String,String> newAddMap = new HashMap<>();//新增的房型
                Map<String,String> nowSearHotelReal = new HashMap<>();//最新查询到的房型数据*/

                Example example = new Example(MtHotelGoodsPrice.class);
                Example.Criteria criteria = example.createCriteria();
                //更新静态信息
                criteria.andEqualTo("mtHotelId", mtHotelId);
                MtHotelDetail mtHotelDetail = mtHotelDetailMapper.selectOneByExample(example);
                if (null != mtHotelDetail) {
                    String localHotelName = mtHotelDetail.getMtHotelName();
                    String localHotelAddress = mtHotelDetail.getMtHotelAddress();
                    String localPhone = mtHotelDetail.getMtPhone();
                    int todo = 0;
                    if (!ObjectUtils.isEmpty(newHotelName) && !newHotelName.equals(localHotelName)) {
                        todo = 1;
                    }
                    if (todo == 0) {
                        if (!ObjectUtils.isEmpty(newHotelAddress) && !newHotelAddress.equals(localHotelAddress)) {
                            todo = 1;
                        }
                    }
                    if (todo == 0) {
                        if (!ObjectUtils.isEmpty(newPhone) && !newPhone.equals(localPhone)) {
                            todo = 1;
                        }
                    }
                    if (todo == 1) {
                        //酒店名称或者地址变更日志表
                        try {
                            MtHotelDetailBasicLog mtHotelDetailBasicLog = new MtHotelDetailBasicLog();
                            mtHotelDetailBasicLog.setId(StringUtil.getUUID());
                            mtHotelDetailBasicLog.setMtHotelId(mtHotelId);
                            mtHotelDetailBasicLog.setMtHotelName(newHotelName);
                            mtHotelDetailBasicLog.setMtHotelAddress(newHotelAddress);
                            mtHotelDetailBasicLog.setMtHotelPhone(newPhone);
                            mtHotelDetailBasicLog.setCreateTime(new Date());
                            mtHotelDetailBasicLog.setState(0);
                            mtHotelDetailBasicLog.setRemark(localHotelName + "_" + localHotelAddress + "_" + newPhone);
                            mtHotelDetailBasicLog.setModifyTime(mtHotelDetailBasicLog.getCreateTime());
                            mtHotelDetailBasicLogMapper.insert(mtHotelDetailBasicLog);
                        } catch (Exception e) {
                            log.error("479保存酒店变更日志异常：" + e.getMessage());
                            e.printStackTrace();
                        }

                    }
                }

                MtHotelDetailExtendInfoPoiExtInfoVo poiExtInfoVo = vo.getExtendInfo().getPoiExtInfo();
                MtHotelDetail entity = new MtHotelDetail();
                entity.setId(String.valueOf(UUID.randomUUID()));
                entity.setMtHotelId(mtHotelId);
                entity.setMtHotelName(newHotelName);
                entity.setMtHotelDesc(thisHotelDetailBaseInfo.getInfo());
                entity.setMtHotelLongitude(String.valueOf(thisHotelDetailBaseInfo.getLongitude()));
                entity.setMtHotelLatitude(String.valueOf(thisHotelDetailBaseInfo.getLatitude()));
                entity.setMtHotelAddress(newHotelAddress);
                entity.setMtHotelCityName(thisHotelDetailBaseInfo.getCityName());
                entity.setMtCityLocationId(String.valueOf(thisHotelDetailBaseInfo.getCityLocationId()));
                entity.setMtLocationName(thisHotelDetailBaseInfo.getLocationName());
                entity.setMtAvgScore(thisHotelDetailBaseInfo.getAvgScore());
                entity.setMtPhone(thisHotelDetailBaseInfo.getPhone());
                entity.setMtOpeninfo(thisHotelDetailBaseInfo.getOpenInfo());
                entity.setMtCloseStatus(thisHotelDetailBaseInfo.getCloseStatus());
                entity.setMtFrontImage(thisHotelDetailBaseInfo.getFrontImage());
                entity.setMtBrandId(thisHotelDetailBaseInfo.getBrandId());
                entity.setMtBrandName(thisHotelDetailBaseInfo.getBrandName());
                entity.setMtOpenDate(poiExtInfoVo.getOpenDate());
                entity.setMtDecorationDate(poiExtInfoVo.getDecorationDate());
                entity.setMtRoomNum(poiExtInfoVo.getRoomNum());
                entity.setMtFloorNum(poiExtInfoVo.getFloorNum());
                entity.setMtHotelStar(poiExtInfoVo.getHotelStar());
                entity.setMtHotelCheckinTimeBegin(poiExtInfoVo.getCheckinTimeBegin());
                entity.setMtHotelCheckinTimeEnd(poiExtInfoVo.getCheckinTimeEnd());
                entity.setMtStatusType(MtHotelEnums.statusTypeEnum.UP.getCode());
                entity.setState(CommonEnums.STATE_NORMAL.getCode());
                entity.setRemark("");
                entity.setCreateTime(now);
                entity.setModifyTime(now);

                entityList.add(entity);

                List<MtHotelDetailRoomInfoVo> thisHotelRoomInfoArr = vo.getRoomInfos();//一个酒店的多组 物理房型+逻辑房型id 数据
                if (null != thisHotelRoomInfoArr && thisHotelRoomInfoArr.size() > 0) {
                    for (MtHotelDetailRoomInfoVo oneRoomInfo : thisHotelRoomInfoArr) {
                        MtHotelDetailBasicRoomRealInfoVo thisOneRoomInfo = oneRoomInfo.getRoomBaseInfo();//有可能酒店详情返回的一组room信息时  逻辑房型id有值，物理房型id没有值（假的房型id有值真的没有值）（没有物理房型id的产品我们不上架）
                        MtHotelDetailBasicRoomRealInfo realInfoEntity = new MtHotelDetailBasicRoomRealInfo();
                        realInfoEntity.setId(StringUtil.getUUID());
                        realInfoEntity.setMtHotelId(thisOneRoomInfo.getHotelId());
                        realInfoEntity.setMtFalseRoomId(thisOneRoomInfo.getRoomId());
                        realInfoEntity.setMtRealRoomId(thisOneRoomInfo.getRealRoomId());
                        realInfoEntity.setState(CommonEnums.STATE_NORMAL.getCode());
                        realInfoEntity.setRemark("");
                        realInfoEntity.setCreateTime(now);
                        realInfoEntity.setModifyTime(now);
                        if (null == realInfoEntity.getMtRealRoomId()) {
                            realInfoEntity.setRemark("当下酒店详情接口返回realRoomId为空");
                            log.info("//////////////// 关系表  realRoomId 为空 赋值 roomId为realRoomId：" + JSON.toJSONString(realInfoEntity));
                        } else {
                            detailBasicRoomEntityList.add(realInfoEntity);
                            //=================》》》2020-11-24 关系表做数据的更新就好，实际上下架是根据room接口保存在room表的物理房型数据     room接口返回的数据 小于等于 关系表数据房型id
                            /*if(null == localRealIdMapFromRelationHotelRoomTable.get(realInfoEntity.getMtRealRoomId())){//数据库没有新的，为新增
                                log.info("存在新增房型id mtHotelId={},realId={}",mtHotelId,realInfoEntity.getMtRealRoomId());
                                newAddMap.put(realInfoEntity.getMtRealRoomId(),realInfoEntity.getMtRealRoomId());
                            }
                            nowSearHotelReal.put(realInfoEntity.getMtRealRoomId(),realInfoEntity.getMtRealRoomId());*/
                        }
                    }

                }

                MtHotelDetailDto mtHotelDetailDto = new MtHotelDetailDto();
                mtHotelDetailDto.setMtHotelId(entity.getMtHotelId());
                mtHotelDetailDto.setMtHotelName(entity.getMtHotelName());
                mtHotelDetailDto.setMtHotelLongitude(entity.getMtHotelLongitude());
                mtHotelDetailDto.setMtHotelLatitude(entity.getMtHotelLatitude());
                mtHotelDetailDto.setMtHotelCityName(entity.getMtHotelCityName());
                mtHotelDetailDto.setMtLocationName(entity.getMtLocationName());
                mtHotelDetailDto.setMtCityLocationId(entity.getMtCityLocationId());
                mtHotelDetailDto.setMtAvgScore(entity.getMtAvgScore());
                mtHotelDetailDto.setMtPhone(entity.getMtPhone());
                mtHotelDetailDto.setMtOpeninfo(entity.getMtOpeninfo());
                mtHotelDetailDto.setMtCloseStatus(entity.getMtCloseStatus());
                mtHotelDetailDto.setMtFrontImage(entity.getMtFrontImage());
                mtHotelDetailDto.setMtBrandId(entity.getMtBrandId());
                mtHotelDetailDto.setMtBrandName(entity.getMtBrandName());
                mtHotelDetailDto.setMtOpenDate(entity.getMtOpenDate());
                mtHotelDetailDto.setMtDecorationDate(entity.getMtDecorationDate());
                mtHotelDetailDto.setMtRoomNum(entity.getMtRoomNum());
                mtHotelDetailDto.setMtFloorNum(entity.getMtFloorNum());
                mtHotelDetailDto.setMtHotelStar(entity.getMtHotelStar());
                mtHotelDetailDto.setMtHotelCheckinTimeBegin(entity.getMtHotelCheckinTimeBegin());
                mtHotelDetailDto.setMtHotelCheckinTimeEnd(entity.getMtHotelCheckinTimeEnd());
                mtHotelDetailDto.setMtStatusType(entity.getMtStatusType());

                redisAppendMap.put(mtHotelDetailDto.getMtHotelId(), mtHotelDetailDto);//entity.getMtHotelLongitude()+entity.getMtHotelLatitude()

                sb.append("'" + mtHotelDetailDto.getMtHotelId() + "'");//拼接单引号,到数据库后台用in查询.
                if (i != voList.size() - 1) {
                    sb.append(",");
                }
            }

            if (null != hotelIds && hotelIds.size() > 0) {
                List<MtHotelRoomDeatilVo> pushSwApiMtRoomList = new ArrayList<>();
                Map<String, String> saleUpFailureMap = new HashMap<>();//上架房型失效了
                Map<String, String> newAddMap = new HashMap<>();//新增的房型
                Map<Long, List<MtHotelRealRoomVo>> allHotelAboutRoomsInfoMap = new HashMap<>();
                for (Long thisHotelId : hotelIds) {
                    //根据hotelid从缓存中获取room信息
                    if (null != redisService.get("sw_mt_hotel_rooms_data_job_push" + thisHotelId)) {//2
                        List<MtHotelRealRoomVo> thisRooms = GsonUtils.jsonToList((String) redisService.get("sw_mt_hotel_rooms_data_job_push" + thisHotelId), MtHotelRealRoomVo.class);
                        allHotelAboutRoomsInfoMap.put(thisHotelId, thisRooms);
                        Map<String, String> thisNewSearchRealRoomMap = new HashMap<>();
                        for (MtHotelRealRoomVo r : thisRooms) {
                            String thisRealRoomId = String.valueOf(r.getRealRoomBaseInfo().getRealRoomId());
                            thisNewSearchRealRoomMap.put(thisRealRoomId, thisRealRoomId);
                        }
                        log.info("该酒店最新查询到的room信息thisNewSearchRealRoomMap={}", GsonUtils.GsonString(thisNewSearchRealRoomMap));
                        //来自房型接口的本地room表的所有的真实房型id，
                        Map<String, String> thisLocalRealIdMapFromRoomApiTable = localRealIdMapFromRoomApiTable(String.valueOf(thisHotelId));//当前数据库保存的房型数据
                        log.info("该酒店room表的信息thisLocalRealIdMapFromRoomApiTable={}", GsonUtils.GsonString(thisLocalRealIdMapFromRoomApiTable));

                        for (Map.Entry<String, String> thisL : thisLocalRealIdMapFromRoomApiTable.entrySet()) {
                            String localRoomId = thisL.getKey();
                            if (null != redisService.get(CommonConstants.SWITCH_SELLING_THE_HOUSE_ROOM_TYPE + thisHotelId + "_" + localRoomId)) {//上架的房型id  ---  自己本地库失效的房型不用校验，因为数据会被更新覆盖
                                if (null == thisNewSearchRealRoomMap.get(localRoomId)) {
                                    //本地库room表的房型id已失效
                                    log.info("存在上架的房型失效，酒店id={}，newRoomId={}", thisHotelId, localRoomId);
                                    MtHotelRoomDeatilVo mtHotelRoomDeatilVo = new MtHotelRoomDeatilVo();
                                    mtHotelRoomDeatilVo.setMtRoomId(Integer.valueOf(localRoomId));//旧的roomid
                                    mtHotelRoomDeatilVo.setGenre(0);
                                    pushSwApiMtRoomList.add(mtHotelRoomDeatilVo);
                                    saleUpFailureMap.put(localRoomId, localRoomId);
                                    MtHotelGoodsRoomUpDownLog mtHotelGoodsRoomUpDownLog = new MtHotelGoodsRoomUpDownLog();
                                    mtHotelGoodsRoomUpDownLog.setId(StringUtil.getUUID());
                                    mtHotelGoodsRoomUpDownLog.setMtHotelId(String.valueOf(thisHotelId));
                                    mtHotelGoodsRoomUpDownLog.setMtRoomId(localRoomId);
                                    mtHotelGoodsRoomUpDownLog.setCreateTime(new Date());
                                    mtHotelGoodsRoomUpDownLog.setType("0");
                                    mtHotelGoodsRoomUpDownLog.setSource("21");
                                    mtHotelGoodsRoomUpDownLogMapper.insert(mtHotelGoodsRoomUpDownLog);

                                }
                            }

                        }

                        for (Map.Entry<String, String> thisN : thisNewSearchRealRoomMap.entrySet()) {
                            String newRoomId = thisN.getKey();
                            if (null == thisLocalRealIdMapFromRoomApiTable.get(newRoomId)) {
                                log.info("存在新增房型，酒店id={}，newRoomId={}", thisHotelId, newRoomId);
                                //最新查询到的房型数据存在新增
                                MtHotelRoomDeatilVo mtHotelRoomDeatilVo = new MtHotelRoomDeatilVo();
                                mtHotelRoomDeatilVo.setMtRoomId(Integer.valueOf(newRoomId));
                                mtHotelRoomDeatilVo.setGenre(1);
                                pushSwApiMtRoomList.add(mtHotelRoomDeatilVo);
                                newAddMap.put(newRoomId, newRoomId);
                                MtHotelGoodsRoomUpDownLog mtHotelGoodsRoomUpDownLog = new MtHotelGoodsRoomUpDownLog();
                                mtHotelGoodsRoomUpDownLog.setId(StringUtil.getUUID());
                                mtHotelGoodsRoomUpDownLog.setMtHotelId(String.valueOf(thisHotelId));
                                mtHotelGoodsRoomUpDownLog.setMtRoomId(newRoomId);
                                mtHotelGoodsRoomUpDownLog.setCreateTime(new Date());
                                mtHotelGoodsRoomUpDownLog.setType("1");
                                mtHotelGoodsRoomUpDownLog.setSource("11");
                                mtHotelGoodsRoomUpDownLogMapper.insert(mtHotelGoodsRoomUpDownLog);

                            }
                        }

                    }

                    if (null != pushSwApiMtRoomList && pushSwApiMtRoomList.size() > 0) {
                        log.info("最终推送room接口对比本地库新增失效房型数据为：" + GsonUtils.GsonString(pushSwApiMtRoomList));
                        MtHotelRoomDownVo mtHotelRoomDownVo = new MtHotelRoomDownVo();
                        mtHotelRoomDownVo.setMtHotelId(thisHotelId.intValue());
                        mtHotelRoomDownVo.setMtRoomList(pushSwApiMtRoomList);
                        redisService.lPush(MeituanConstants.REDIS_QUEUE_BASIC_REAL_ROOM_UPDATE_TO_SWITCHS, GsonUtils.GsonString(mtHotelRoomDownVo));
                        SendUtils.dingMsgNotLog("[HOTEL-API-ROOM-UPDATE]", "room接口比对本地库，存在变化push到队列，等待定时器消费推送携程：上架失效房型=" + GsonUtils.GsonString(saleUpFailureMap) + " 新增房型=" + GsonUtils.GsonString(newAddMap) + " 酒店id=" + thisHotelId, MessageEnums.genre.GOODS_STATUS_AND_PRICE.getCode(), restTemplate);
                    }
                }
                if (null == redisService.get("hotel_room_update_table_basic_close")) {//有时候需要测试 不更新本地库表 设置开关
                    if (null != allHotelAboutRoomsInfoMap && allHotelAboutRoomsInfoMap.size() > 0) {
                        mtHotelRoomService.saveRoomData(allHotelAboutRoomsInfoMap);
                    }
                }

            }

            if (null == redisService.get("save_hotel_basie_close")) {//测试阶段 需要本地库数据进行房型比对和酒店比对，前期阶段需要开关不更新酒店相关静态信息
                //mtHotelDetailInfoMapper.insertList(entityList);
                //旧数据删除，插入新数据
                Map map = new HashMap();
                map.put("hotelIds", sb.toString());
                int delDel = mtHotelDetailMapper.deleteBatch(map);
                if (delDel != -1) {
                    mtHotelDetailMapper.insertList(entityList);
                }

                int roDel = mtHotelDetailBasicRoomRealInfoMapper.deleteBatch(map);
                if (roDel != -1) {
                    mtHotelDetailBasicRoomRealInfoMapper.insertList(detailBasicRoomEntityList);
                }
            }

            //将所有酒店数据缓存到redis，对比数据使用
            //redisSaveUpdateMtHotelInfos(redisAppendMap);
            return new Result<>();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return new Result<>(e.getMessage(), CommonConstants.REQUEST_ERROR);
        }
    }

    /**
     * redis 缓存酒店数据
     * Map appendMap    key = 酒店id，value=酒店dto对象
     *
     * @param appendMap
     */
    @Override
    public void redisSaveUpdateMtHotelInfos(Map appendMap) {
        Map<String, MtHotelDetailDto> redisMap = (Map<String, MtHotelDetailDto>) redisService.get(CommonConstants.MEITUAN_HOTEL_INFO);
        if (null != redisMap && redisMap.size() > 0) {
            redisMap.putAll(appendMap);//加入putall覆盖旧数据
        } else {
            redisMap = appendMap;
        }
        redisService.set(CommonConstants.MEITUAN_HOTEL_INFO, redisMap);
    }

    //
    @Override
    public Result<Object> findAllHotelIdsPutRedis() {
        Example example = new Example(MtHotel.class);
        /*example.createCriteria().andCondition("switch_hotel_id=", masterHotelId)
                .andCondition("is_compare = 1");*/
        List<MtHotel> list = mtHotelMapper.selectByExample(example);
        //美团ids缓存key = MeituanConstants.REDIS_MT_HOTEL_IDS
        Map<String, String> putRedisMap = new HashMap<>();
        for (MtHotel vo : list) {
            String hotelId = vo.getMtHotelId();
            putRedisMap.put(String.valueOf(hotelId), String.valueOf(hotelId));
            redisTemplate.opsForList().leftPush("LEFT_PUSH_" + MeituanConstants.REDIS_MT_HOTEL_IDS, hotelId);
        }//

        Map<String, String> redisMap = (Map<String, String>) redisTemplate.opsForValue().get(MeituanConstants.REDIS_MT_HOTEL_IDS);
        if (null != redisMap && redisMap.size() > 0) {
            redisMap.putAll(putRedisMap);
        } else {
            redisMap = putRedisMap;
        }

        redisTemplate.opsForValue().set(MeituanConstants.REDIS_MT_HOTEL_IDS, redisMap);
        return new Result<>();
    }

    @Override
    public Result<Object> checkHotelFailure(List<Long> hotelIds) {
        List<MtHotelDownVo> mtHotelDownVoList = new ArrayList<>();//美团酒店主信息vo
        Map<String, String> apiMtHotelMap = new HashMap<>();

        Result rs = getMtHotelDetail(hotelIds, null);//请求获取酒店详情数据
        if (rs.getCode() == CommonConstants.SUCCESS) {
            List<MtHotelDetailVo> voList = (List<MtHotelDetailVo>) rs.getData();
            if (null != voList && voList.size() > 0) {
                for (MtHotelDetailVo v : voList) {
                    String mtHotelId = String.valueOf(v.getBaseInfo().getHotelId());
                    apiMtHotelMap.put(mtHotelId, mtHotelId);
                    if (0 == v.getBaseInfo().getCloseStatus()) {
                        /**
                         * 酒店营业状态：
                         * 0 营业中
                         * 1 已关门
                         * 2 筹建中
                         * 3 暂停营业
                         */
                        //mtHotelDownVo.setStatus(1);

                        //上线的不用推送 下线的才推送

                    } else {
                        //推送

                        MtHotelDownVo mtHotelDownVo = new MtHotelDownVo();
                        mtHotelDownVo.setMtHotelId(mtHotelId);
                        mtHotelDownVo.setStatus(0);
                        try {
                            MtHotelDetail updateMtHotelDetail = new MtHotelDetail();
                            updateMtHotelDetail.setMtHotelId(String.valueOf(mtHotelId));
                            updateMtHotelDetail.setMtStatusType(0); //酒店上下线，默认上线1  下线 0

                            MtHotelDetailOperLog insertMtHotelDetailOperLog = new MtHotelDetailOperLog();
                            insertMtHotelDetailOperLog.setMtHotelId(String.valueOf(mtHotelId));
                            insertMtHotelDetailOperLog.setState(0);
                            insertMtHotelDetailOperLog.setType(0);//营业状态 为非开店
                            this.updateStateTypeByHotelId(updateMtHotelDetail, insertMtHotelDetailOperLog);
                        } catch (Exception e) {
                            log.error("外放酒店校验接口，处理失败：" + e.getMessage());
                            e.printStackTrace();
                        }

                        mtHotelDownVoList.add(mtHotelDownVo);
                    }

                }
                for (Long m : hotelIds) {
                    if (null == apiMtHotelMap.get(String.valueOf(m))) {
                        MtHotelDownVo mtHotelDownVo = new MtHotelDownVo();
                        mtHotelDownVo.setMtHotelId(String.valueOf(m));
                        mtHotelDownVo.setStatus(0);//美团查无信息 也为下线  下线酒店美团接口返回空
                        mtHotelDownVoList.add(mtHotelDownVo);
                        try {
                            MtHotelDetail updateMtHotelDetail = new MtHotelDetail();
                            updateMtHotelDetail.setMtHotelId(String.valueOf(m));
                            updateMtHotelDetail.setMtStatusType(0); //酒店上下线，默认上线1  下线 0

                            MtHotelDetailOperLog insertMtHotelDetailOperLog = new MtHotelDetailOperLog();
                            insertMtHotelDetailOperLog.setMtHotelId(String.valueOf(m));
                            insertMtHotelDetailOperLog.setState(0);
                            insertMtHotelDetailOperLog.setType(1);//酒店查无信息
                            this.updateStateTypeByHotelId(updateMtHotelDetail, insertMtHotelDetailOperLog);
                        } catch (Exception e) {
                            log.error("外放酒店校验接口，处理失败：" + e.getMessage());
                            e.printStackTrace();
                        }
                    }
                }
            } else {
                for (Long m : hotelIds) {
                    MtHotelDownVo mtHotelDownVo = new MtHotelDownVo();
                    mtHotelDownVo.setMtHotelId(String.valueOf(m));
                    mtHotelDownVo.setStatus(0);//美团查无信息  也为下线
                    mtHotelDownVoList.add(mtHotelDownVo);
                    try {
                        MtHotelDetail updateMtHotelDetail = new MtHotelDetail();
                        updateMtHotelDetail.setMtHotelId(String.valueOf(m));
                        updateMtHotelDetail.setMtStatusType(0); //酒店上下线，默认上线1  下线 0
                        MtHotelDetailOperLog insertMtHotelDetailOperLog = new MtHotelDetailOperLog();
                        insertMtHotelDetailOperLog.setMtHotelId(String.valueOf(m));
                        insertMtHotelDetailOperLog.setState(0);
                        insertMtHotelDetailOperLog.setType(1);//酒店查无信息
                        this.updateStateTypeByHotelId(updateMtHotelDetail, insertMtHotelDetailOperLog);
                    } catch (Exception e) {
                        log.error("外放酒店校验接口，处理失败：" + e.getMessage());
                        e.printStackTrace();
                    }
                }
            }

            return new Result<>(GsonUtils.GsonString(mtHotelDownVoList), "success");

        } else {
            return new Result<>("接口返回失败：" + GsonUtils.GsonString(rs));
        }
    }

    @Override
    public Result getHHbDownHotels() {
       /* Example example = new Example(MtHotel.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("type",2);//被主动查询下线的酒店
        criteria.andGreaterThan("createTime",DateUtil.formatDate(DateUtil.addMonth(new Date(),-1),"yyyy-MM-dd HH:mm:ss"));*/
        Map map = new HashMap();
        map.put("type", 2);
        map.put("modifyTime", DateUtil.formatDate(DateUtil.addMonth(new Date(), -1), "yyyy-MM-dd HH:mm:ss"));
        List<MtHotel> list = mtHotelMapper.getHHbDownHotels(map);
        List<String> ids = new ArrayList<>();
        for (MtHotel h : list) {
            ids.add(h.getMtHotelId());
        }
        return new Result(ids, "success");

    }

    @Override
    public void updateStateTypeByHotelId(MtHotelDetail mtHotelDetail, MtHotelDetailOperLog insertMtHotelDetailOperLog) {
        //更新酒店数据库信息
        /*mtHotelDetailMapper.updateStateTypeByHotelIds(map);
        Integer statusType = (Integer)map.get("statusType");
        String idsStr = (String)map.get("hotelIds");*/
       /* mtHotelDetail.setModifyTime(new Date());
        Example example = new Example(MtHotelOrderBooking.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("mtHotelId",mtHotelDetail.getMtHotelId());
        mtHotelDetailMapper.updateByExampleSelective(mtHotelDetail,example);*/

        MtHotelDetailOperLog mtHotelDetailOperLog = new MtHotelDetailOperLog();
        if (null != insertMtHotelDetailOperLog) {
            BeanCopierUtil.copy(insertMtHotelDetailOperLog, mtHotelDetailOperLog);
        } else {
            mtHotelDetailOperLog.setMtHotelId(mtHotelDetail.getMtHotelId());
            mtHotelDetailOperLog.setState(mtHotelDetail.getMtStatusType());
            mtHotelDetailOperLog.setRemark(mtHotelDetail.getRemark());
        }
        updateStateHotelLog(mtHotelDetailOperLog);

    }

    public void updateStateHotelLog(MtHotelDetailOperLog mtHotelDetailOperLog) {
        mtHotelDetailOperLog.setCreateTime(new Date());
        mtHotelDetailOperLog.setId(StringUtil.getUUID());
        mtHotelDetailOperLogMapper.insert(mtHotelDetailOperLog);
    }
}
